import 'package:bruno/bruno.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/yt_button.dart';
import 'package:yt_devops/components/yt_input.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/log_record/sqlite_test.dart';
import 'package:yt_devops/components/my_gesture_detector.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'login_controller.dart';

class LoginPage extends GetView<LoginController> {
  const LoginPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LoginController>(
      builder: (controller) => Scaffold(
        resizeToAvoidBottomInset: false,
        backgroundColor: Colour.white,
        appBar: AppBar(
          backgroundColor: Colour.white,
          iconTheme: const IconThemeData(color: Colour.black),
          actions: [
            MyGestureDetector(
                onTap: () {
                  controller.showPop();
                },
                child: Container(
                  color: Colors.white,
                  width: 200,
                  child: Row(
                    children: [
                      Spacer(),
                      Container(
                        margin: const EdgeInsets.only(top: 2, right: 5),
                        child: Text(
                          controller.languageList[controller.selectedIndex],
                          style: ytTextStyle(fontSize: 14),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(right: 24.w),
                        child: Image.asset(
                          'assets/images/login_change_language_arrow_down.png',
                          width: 14.w,
                          height: 14.w,
                          color: controller.isShowPop
                              ? Colour.primaryColor
                              : Colour.lightTextColor,
                          // color: Colour.mainTextColor,
                        ),
                      )
                    ],
                  ),
                ))
          ],
        ),
        body: Stack(
          children: [
            Container(
              padding: EdgeInsets.fromLTRB(
                  32.w, controller.isRelease ? 60 : 0.h, 32.w, 45.h),
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Visibility(
                      visible: !controller.isRelease,
                      child: GestureDetector(
                        behavior: HitTestBehavior.opaque,
                        onTap: () {
                          controller.changeEnvironment();
                        },
                        child: SizedBox(
                          // color: Colors.red,
                          height: 60.h,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                children: [
                                  Text(
                                    ResKey.checkEnv.tr,
                                    style: ytTextStyle(fontSize: 20),
                                  ),
                                  Image.asset(
                                    'assets/images/right_arrow.png',
                                    width: 30.w,
                                    height: 30.w,
                                    color: Colour.mainTextColor,
                                  ),
                                ],
                              ),
                              Text(
                                '${ResKey.current.tr}: ${controller.environmentString}',
                                style: ytTextStyle(
                                    fontSize: 15, color: Colour.primaryColor),
                              )
                            ],
                          ),
                        ),
                      ),
                    ),
                    Text(
                      ResKey.login.tr,
                      style: TextStyles.f30.boldStyle,
                    ),
                    SizedBox(
                      height: 48.h,
                    ),
                    YtInput(
                        border: const UnderlineInputBorder(
                            borderSide: BorderSide(color: Color(0xFFEEEEEE))),
                        textAlign: TextAlign.left,
                        placeholderText: ResKey.enterAccountName.tr,
                        placeholderTextStyle: ytTextStyle(
                            fontSize: 14, color: Colour.hintTextColor),
                        inputTextStyle: TextStyles.f14,
                        controller: controller.nameController,
                        searchController: controller.searchTextController,
                        // focusNode: controller.focusNode,
                        onTextClear: () {
                          controller.textOnchange('');
                          return false;
                        },
                        onChanged: controller.textOnchange),
                    SizedBox(
                      height: 15.h,
                    ),
                    YtInput(
                        border: const UnderlineInputBorder(
                            borderSide: BorderSide(color: Color(0xFFEEEEEE))),
                        textAlign: TextAlign.left,
                        placeholderText: ResKey.enterAccountPwd.tr,
                        placeholderTextStyle: ytTextStyle(
                            fontSize: 14, color: Colour.hintTextColor),
                        inputTextStyle: TextStyles.f14,
                        inputType: YtInputType.password,
                        controller: controller.pwdController,
                        // focusNode: controller.pwdFocusNode,
                        onChanged: controller.textOnchange),
                    SizedBox(
                      height: 40.h,
                    ),
                    YtButton(
                      size:  Size(311.w, 50),
                      enabled: controller.enable,
                      diableColor: Theme.of(context).primaryColorLight,
                      text: ResKey.login.tr,
                      onPress: () => controller.login(context),
                    ),
                    const SizedBox(
                      height: 24,
                    ),
                    // Row(
                    //   children: [
                    //     Spacer(),
                    //     GestureDetector(
                    //       onTap: () {
                    //         controller.visitorLogin(context);
                    //       },
                    //       child: Text(
                    //         ResKey.visitorMode.tr,
                    //         style: ytTextStyle(
                    //             color: Colour.otherTextColor, fontSize: 14),
                    //       ),
                    //     ),
                    //     Spacer(),
                    //   ],
                    // ),
                    // Container(
                    //   height:500,
                    //   child: SqlitePage(),
                    // ),
                    Expanded(
                      child: Align(
                        alignment: Alignment.bottomCenter,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            SizedBox(
                              key: controller.leftKey,
                              child: BrnCheckbox(
                                behavior: HitTestBehavior.opaque,
                                radioIndex: 0,
                                mainAxisSize: MainAxisSize.max,
                                isSelected: controller.isAgree,
                                onValueChangedAtIndex: controller.agreePolicy,
                              ),
                            ),
                            InkWell(
                              onTap: controller.toPolicy,
                              child: Text.rich(
                                TextSpan(
                                    text: ResKey.readAndAgree.tr,
                                    style: TextStyles.lf14,
                                    children: [
                                      TextSpan(
                                          text: '《${ResKey.privatePolicy.tr}》',
                                          style: TextStyles.pf14)
                                    ]),
                              ),
                            )
                          ],
                        ),
                      ),
                    ),
                  ]),
            ),
            Visibility(
                visible: controller.isShowPop,
                child: Positioned(
                    right: 15.w,
                    child: Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(6),
                        boxShadow: const [
                          BoxShadow(
                            color: Colour.borderColor, // 设置阴影颜色
                            blurRadius: 10, // 阴影模糊程度
                            offset: Offset(0, 4), // 阴影偏移量
                          ),
                        ],
                        border:
                            Border.all(color: Colour.borderColor, width: 0.5),
                        color: Colors.white,
                      ),
                      height: 80,
                      width: 95,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          MyGestureDetector(
                              onTap: () {
                                controller.changeLanguage(0);
                              },
                              child: Container(
                                margin: EdgeInsets.only(top: 12),
                                alignment: Alignment.center,
                                child: Text(
                                  controller.languageList[0],
                                  style: ytTextStyle(
                                      fontSize: 14,
                                      color: controller.selectedIndex == 0
                                          ? Colour.primaryColor
                                          : Colour.mainTextColor),
                                ),
                              )),
                          Spacer(),
                          MyGestureDetector(
                            onTap: () {
                              controller.changeLanguage(1);
                            },
                            child: Container(
                              margin: EdgeInsets.only(bottom: 12),
                              alignment: Alignment.center,
                              child: Text(
                                controller.languageList[1],
                                style: ytTextStyle(
                                    fontSize: 14,
                                    color: controller.selectedIndex == 1
                                        ? Colour.primaryColor
                                        : Colour.mainTextColor),
                              ),
                            ),
                          )
                        ],
                      ),
                    )))
          ],
        ),
      ),
    );
  }
}
